/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

import net.sourceforge.perforce.api.IError;
import net.sourceforge.perforce.api.Policy;

/**
 * Wrapper class for Perforce API Error class.
 * 
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net>Boris
 *         Pruessmann</a>
 */
public final class Error implements IError {

  /**
   * Used to store the native reference. <br>
   * DON'T TOUCH THE CONTENT OF THIS VARIABLE
   */
  @SuppressWarnings("unused")
  private int _nativeHandle;

  /** Constructor for Error. */
  public Error() {
    construct();
  }

  /** Disposes the Error object, freeing native resources. */
  public void dispose() {
    destruct();
  }

  public native void clear();

  public native boolean test();

  public native boolean isInfo();

  public native boolean isWarning();

  public native boolean isFatal();

  public native boolean isError();

  public native int getSeverity();

  public native int getGeneric();

  public native String formatSeverity();

  public native String format(int options);

  @Override
  public String toString() {
    Object[] values =
        new Object[] {new Integer(getSeverity()), new Integer(getGeneric()),
            format(IError.EF_PLAIN),};

    return Policy.bind("Error.toString", values); //$NON-NLS-1$
  }

  /**
   * Call this method to create the native Error object.
   */
  private native void construct();

  /**
   * Call this method to destroy the native Error object.
   */
  private native void destruct();
}
